package com.itheima.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String EXCHANGE_NAME="boot_topic_exchange";
    public static final String QUEUE_NAME="boot_queue";

    //1.交换机
    @Bean
    public Exchange bootExchange(){
        //durable：是否持久化
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    //2.队列
    @Bean
    public Queue bootQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }


    //3.队列与交换机的关系，Binding对象
    @Bean
    public Binding bindQueueExchange(@Qualifier("bootExchange") Exchange exchange,@Qualifier("bootQueue") Queue queue){
        //with后面为routingKey
        return BindingBuilder.bind(queue).to(exchange).with("boot.#").noargs();
    }
}
